package com.gsit.ocrbatch.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

import com.gsit.ocrbatch.utils.MessageUtil;

@Entity
@NamedQueries({@NamedQuery ( name="findByAllWaitingRecords" ,query="SELECT record FROM Record record where record.recordState =:recordState ")})
public class Record {
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	
	@Column
	private String name;
	
	@Column
	private String path;
	
	@Column
	private int count;
	
	
	@Column(name = "recordState", nullable = false)
	@Enumerated(EnumType.STRING)
	private RecordState recordState;
	
	
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
	@JoinColumn(name="r_id")
    private List<RecordReject> recordRejects;
	
	public void setRecordRejectAll(List<String> states){
		recordRejects = new ArrayList<RecordReject>();
		if(states == null ) return;
		for (String state : states) {
			recordRejects.add(new RecordReject(MessageUtil.getMessage(RejectState.valueOf(state)),RejectState.valueOf(state)));
		}
	}
	
	public List<String> getRecordRejectAll(){
		return new ArrayList<String>();
	}

	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public RecordState getRecordState() {
		return recordState;
	}

	public void setRecordState(RecordState recordState) {
		this.recordState = recordState;
	}

	public List<RecordReject> getRecordRejects() {
		return recordRejects;
	}

	public void setRecordRejects(List<RecordReject> recordRejects) {
		this.recordRejects = recordRejects;
	}

	

}
